package com.alpha.eceasy.mall.controller;

import com.alpha.eceasy.core.R;
import com.alpha.eceasy.mall.api.dto.MallImDTO;
import com.alpha.eceasy.mall.api.entity.MallIm;
import com.alpha.eceasy.mall.api.vo.MallImVO;
import com.alpha.eceasy.mall.service.impl.MallImServiceImpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 聊天会话 前端控制器
 * </p>
 *
 * @author huangpengfei
 * @since 2024-05-15
 */
@RestController
@RequestMapping("/mall-im")
@Tag(description = "mall-im", name = "聊天会话")
public class MallImController {
    @Resource
    private MallImServiceImpl imService;

    /**
     * 分页查询
     *
     * @param page 分页对象
     * @param im   聊天会话
     * @return 分页结果
     */
    @Hidden
    @Operation(description = "分页查询", summary = "分页查询")
    @GetMapping("")
    public R<IPage<MallIm>> page(Page<MallIm> page, MallIm im) {
        return R.ok(imService.page(page, Wrappers.query(im)));
    }

    /**
     * 通过订单guid查询聊天会话
     *
     * @param orderGuid 订单guid
     * @return R 返回结果 聊天会话
     */
    @Operation(description = "通过订单guid查询", summary = "通过订单guid查询")
    @GetMapping("/{orderGuid}")
    public R<MallImVO> getByGuid(@PathVariable("orderGuid") String orderGuid) {
        return R.ok(imService.getVOByGuid(orderGuid));
    }

    /**
     * 新增聊天会话
     *
     * @param dto 聊天会话
     * @return R 返回结果 是否成功
     */
    @Operation(description = "新增聊天会话", summary = "新增聊天会话")
    //@SysLog("新增聊天会话")
    @PostMapping
    public R<Boolean> save(@RequestBody MallImDTO dto) {
        return R.ok(imService.save(dto));
    }

    /**
     * 通过guid修改聊天会话
     *
     * @param im 聊天会话
     * @return R 返回结果 是否成功
     */
    @Hidden
    @Operation(description = "修改聊天会话", summary = "修改聊天会话")
    //@SysLog("修改聊天会话")
    @PutMapping
    public R<Boolean> updateByGuid(@RequestBody MallIm im) {
        return R.ok(imService.updateByGuid(im));
    }

    /**
     * 通过guid删除聊天会话
     *
     * @param guid guid
     * @return R 返回结果
     */
    //@SysLog("通过id删除聊天会话")
    @Hidden
    @Operation(description = "通过guid删除聊天会话", summary = "通过guid删除聊天会话")
    @DeleteMapping("/{guid}")
    public R<Boolean> removeById(@PathVariable String guid) {
        return R.ok(imService.removeByGuid(guid));
    }

}
